/*
 *  Menu
 */
package DatabaseTest;

import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author Ray
 */
public class Menu {

    int maxmenu = 5;
    Performer p = new Performer();
    String[] actions = {"Show ID info", "Show Transaction Info",
        "Update Entry", "Show Summary"};

    public Menu() {
        startMenu();
    }

    private void startMenu() {
        int option;
        boolean finish = false;
        while (!finish) {
            printMenu();
            option = readOption();
            switch (option) {
                case 1: {
                    p.showID();
                    break;
                }
                case 2: {
                    p.showTransaction();
                    break;
                }
                case 3: {
                    p.updateEntry();
                    break;
                }
                case 4: {
                    p.summary();
                    break;
                }
                case 5: {
                    System.out.println("Thanks and Goodbye!");
                    finish = true;
                    break;
                }
            }
        }
    }

    private void printMenu() {
        System.out.println("Please Choose One Action to Perform by Typing"
                + " the Option Number and Press 'Enter'.");
        int i = 1;
        for (String s : actions) {
            System.out.println(i + ": " + s + ".");
            i++;
        }
        System.out.println("5: Quit.");
        System.out.print("Your Input is:");
    }

    private int readOption() {
        Scanner scan = new Scanner(System.in);
        String option;
        int optionNum = -1;
        if (scan.hasNextLine()) {
            option = scan.nextLine();
            try {
                optionNum = Integer.valueOf(option);
            } catch (NumberFormatException e) {
                System.out.println("Invalid Input!");
                return -1;
            }
            if (optionNum < 1 || optionNum > maxmenu) {
                System.out.println("Invalid Input!");
                return -1;
            }
        } else {
            System.out.println("Nothing Input!");
        }
        return optionNum;
    }

}
